package com.lcy.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.eb.service.IndexService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("index")
public class indexController {
    @Resource
    private IndexService indexService;
    @RequestMapping("index")
    public String index(Model model,
                        @RequestParam(value="psize",defaultValue = "1") int psize,
                        @RequestParam(value="pageSize",defaultValue = "8") int pageSize){
        Map<String, Page> result = indexService.index(psize, pageSize);
        model.addAttribute("result",result);
        System.out.println("接收到一个浏览器的请求");
        return "index";
    }

    @RequestMapping("category")
    public String category(Model model,
                           int epId,
                           @RequestParam(value="psize",defaultValue = "1") int psize,
                           @RequestParam(value="pageSize",defaultValue = "8") int pageSize){
        Map<String, Page> categoryProductPage = indexService.category(epId, psize, pageSize);
        model.addAttribute("categoryResult",categoryProductPage);
        return "product-list";
    }
}
